/*
 * COPYRIGHT (C) 2009 ISB Vietnam Company Ltd.
 *
 * No.     Date          Name            Description
 * 001.    09/04/29      TuanNguyen      Newly created.
 * 002.    09/05/11      TuanNguyen      [ID_0005363] Fixed open page not true.
 * 003.    09/05/13      TuanNguyen      [ID_003] Support for G1.
 * 004.    09/05/14      hbtri           [CHR_002] help, about
*/
package com.ivc.android.maps;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;

/**
 * Webview class to show map that load from map.google.com.
 * @author tuannguyen
 */
public class WebAPIMap extends Activity {
    /* 090514-[ID_003] - ADD[S] */
    /**
     * zoom in button.
     */
    private ImageButton zoomInBtn;
    /**
     * zoom out button.
     */
    private ImageButton zoomOutBtn;
    /**
     * width between zoom in and out.
     */
    private static final int ZOOM_CTRL_WIDTH = 40;
    /**
     * G1 screen size width- landscape - 480.
     */
    private static final int G1_SCR_SIZE_WIDTH_L = 480;
    /**
     * G1 screen size width - 320.
     */
    private static final int G1_SCR_SIZE_WIDTH = 320;
    /**
     * zoom in mark layout param.
     */
    private static final FrameLayout.LayoutParams ZOOM_IN_PARAMS =
        new FrameLayout.LayoutParams(
          ViewGroup.LayoutParams.WRAP_CONTENT,
          ViewGroup.LayoutParams.WRAP_CONTENT,
          Gravity.BOTTOM);
    /**
     * zoom in mark layout param.
     */
    private static final FrameLayout.LayoutParams ZOOM_OUT_PARAMS =
        new FrameLayout.LayoutParams(
          ViewGroup.LayoutParams.WRAP_CONTENT,
          ViewGroup.LayoutParams.WRAP_CONTENT,
          Gravity.BOTTOM);
    /* 090514-[ID_003] - ADD[E] */
    /**
     * progress dialog.
     */
    private ProgressDialog myMapProgress;
    /**
     * search place menu.
     */
    private static final int MENU_SEARCH_ID = 0;
    /* 090514-[ID_003] - DEL[S] */
//    /**
//     * stop search place.
//     */
//    private static final int MENU_STOP_SEARCH_ID = 1;
    /* 090514-[ID_003] - DEL[E] */
    /**
     * normal map.
     */
    private static final int MENU_MAP_ID = 2;
    /**
     * Satellite map.
     */
    private static final int MENU_SATELLITE_MAP_ID = 3;
    /**
     * Phy map.
     */
    private static final int MENU_PHY_MAP_ID = 4;
    /**
     * hybird map.
     */
    private static final int MENU_HYBIRD_MAP_ID = 5;
    /* 090514-[CHR_002]-ADD[S]*/
    /**
     * help map.
     */
    private static final int MENU_HELP_MAP_ID = 6;
    /**
     * about map.
     */
    private static final int MENU_ABOUT_MAP_ID = 7;
    /* 090514-[CHR_002]-ADD[E]*/
    /**
     * max progress.
     */
    private static final int MAX_PROGRESS = 100;
    /**
     * webview - show web content - map content.
     */
    private WebView webView;
    /* 090514-[ID_003] - DEL[S] */
//    /**
//     * store menu.
//     */
//    private Menu menuView;
    /* 090514-[ID_003] - DEL[E] */
    /**
     * handler for javascript.
     */
    private Handler mHandler = new Handler();
    /**
     * image viewer.
     */
    private ImageView imageView;
    /* 090514-[CHR_002]-ADD[S]*/
    /**
     * title-dialog help.
     */
    private static final String DIALOG_HELP_TITLE = "Ajuda";
    /**
     * title-dialog about.
     */
    private static final String DIALOG_ABOUT_TITLE = "Sobre o GoAround";
    /**
     * menu-search title.
     */
    private static final String MENU_HELP_TITLE = "Ajuda";
    /**
     * menu-about title.
     */
    private static final String MENU_ABOUT_TITLE = "Sobre";
    /* 090514-[CHR_002]-ADD[E]*/
    /**
     * menu-search title.
     */
    private static final String MENU_SEARCH_TITLE = "Procurar Local";
    /**
     * menu-stop search title.
     */
    private static final String MENU_STOP_SEARCH_TITLE = "Parar Busca";
    /**
     * menu-Satellite map title.
     */
    private static final String MENU_SATELLITE_TITLE = "Mapa Satelite";
    /**
     * menu-hybird map title.
     */
    private static final String MENU_HYBIRD_TITLE = "Mapa Hibrido";
    /**
     * menu-Terrain map title.
     */
    private static final String MENU_TERRIAN_TITLE = "Mapa Terreno";
    /**
     * menu-map title.
     */
    private static final String MENU_MAP_TITLE = "Mapa";
    /**
     * progress bar title.
     */
    private static final String PRO_TITLE = "Carregando o Google Maps";
    /**
     * progress bar content.
     */
    private static final String PRO_CONTENT = "Por favor aguarde...";

    /**
     * web api.
     */
    private static final String WEB_API_HTML = "file:///android_asset/WebAPIJavaScript.html";
    /**
     * Called when the activity is first created.
     * @param savedInstanceState Instance
     * */
    @Override
    public final void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /* 090513-[ID_003]-DEL[S]-Don't need to show progress bar on title*/
        //requestWindowFeature(Window.FEATURE_PROGRESS);
        //setProgressBarVisibility(true);
        /* 090513-[ID_003]-DEL[S]*/
        //no title bar.
        setTheme(android.R.style.Theme_Black_NoTitleBar);
        setContentView(R.layout.main);
        //set detector.
       //set image on top.
        setImageLayout();
        //set webview below image.
        setWebViewLayout();
        /* 090514-[ID_003]-ADD[S]- Support long press on screen to show Zoom control. */
        applyMapViewLongPressListener();
        /* 090514-[ID_003]-ADD[E]- Support long press on screen to show Zoom control. */
        //set onkey event
        enableMoveHotKey();
        updateMap();
    }
    /* 090514-[ID_003]-ADD[S]- Support long press on screen to show Zoom control. */
    /**
     * apply map view with long press.
     */
    private void applyMapViewLongPressListener() {
        final GestureDetector gd = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
             @Override
             public void onLongPress(final MotionEvent e) {
                 // TODO Auto-generated method stub
                 if (zoomInBtn.getVisibility() == View.VISIBLE) {
                     zoomInBtn.setVisibility(View.GONE);
                     zoomOutBtn.setVisibility(View.GONE);
                 } else {
                     zoomInBtn.setVisibility(View.VISIBLE);
                     zoomOutBtn.setVisibility(View.VISIBLE);
                 }
             }
        });
        this.webView.setOnTouchListener(new OnTouchListener() {
             public boolean onTouch(final View v, final MotionEvent ev) {
                  return gd.onTouchEvent(ev);
             }
        });
   }
    /* 090514-[ID_003]-ADD[E]- Support long press on screen to show Zoom control. */
    /**
     * Get width screen size.
     * @return width size.
     */
    private int getWidthScreenSize() {
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        return dm.widthPixels;
    }
    /**
     * set image layout.
     */
    private void setImageLayout() {
        imageView = (ImageView) findViewById(R.id.title);
        /* 090513-[ID_003]-ADD[S]- Support title for G1 screen */
        setTitleImageWithSize();
        /* 090513-[ID_003]-ADD[E]- Support title for G1 screen */
        imageView.setVisibility(View.VISIBLE);
    }
    /* 090513-[ID_003]-ADD[S]- Support title for G1 screen */
    /**
     * Set title image size.
     */
    private void setTitleImageWithSize() {
        int widthScr = getWidthScreenSize();
        if (widthScr == G1_SCR_SIZE_WIDTH) {
            imageView.setBackgroundResource(R.drawable.title320);
        } else if (widthScr == G1_SCR_SIZE_WIDTH_L) {
            imageView.setBackgroundResource(R.drawable.title480);
        }
    }
    /**
     * when user press Numpad_7 or 9 to change view - orientation.
     * @param newConfig configuration.
     */
    @Override
    public final void onConfigurationChanged(final Configuration newConfig) {
        // TODO Auto-generated method stub
        super.onConfigurationChanged(newConfig);
        setTitleImageWithSize();
        /* 090514-[ID_003]-ADD[S] */
        setZoomParamMargin();
        /* 090514-[ID_003]-ADD[E] */
    }
    /* 090513-[ID_003]-ADD[S] */
    /**
     * set webview layout.
     */
    private void setWebViewLayout() {
        //create webview
        webView = (WebView) findViewById(R.id.webview);
        /* 090513-[ID_003]-CHG[S]-Allow touch on screen */
        //webView.setClickable(false);
        webView.setClickable(true);
        /* 090513-[ID_0003]-CHG[E] */
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        //listener
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(final WebView view, final String url) {
                myMapProgress.dismiss();
            }
            /* 090511-[ID_0005363]-ADD[S]-Override all link*/
            @Override
            public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
              /* intercept all page load attempts and load yahoo.com instead */
                return true;
            }
            /* 090511-[ID_0005363]-ADD[E]-Override all link*/
        });
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(final WebView view
                    , final int newProgress) {
                setProgress(newProgress * MAX_PROGRESS);
            }
        });
        /* 090513-[ID_003]-ADD[S]- Support zoom control for webview */
        createZoomCtrl();
        /* 090513-[ID_003]-ADD[E]*/
    }
    /* 090513-[ID_003]-ADD[S] - set zoom control layout. */
    /**
     * Config zoom param margin.
     */
    private void setZoomParamMargin() {
        int widthScr = getWidthScreenSize();
        ZOOM_OUT_PARAMS.leftMargin = widthScr / 2 + ZOOM_CTRL_WIDTH / 2;
        ZOOM_IN_PARAMS.leftMargin = widthScr / 2 - ZOOM_CTRL_WIDTH * 2;
    }
    /* 090513-[ID_003]-ADD[E]*/

    /* 090513-[ID_003]-ADD[S]- Support zoom control for webview */
    /**
     * create zoom ctrl.
     */
    private void createZoomCtrl() {
        setZoomParamMargin();
        FrameLayout mContentView = (FrameLayout) getWindow().getDecorView()
                                                            .findViewById(android.R.id.content);
        //create zoomOut button.
        zoomOutBtn = new ImageButton(webView.getContext());
        zoomOutBtn.setImageResource(R.drawable.zoomout1);
        zoomOutBtn.setVisibility(View.GONE);
        mContentView.addView(zoomOutBtn, ZOOM_OUT_PARAMS);
        zoomOutBtn.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(final View v, final MotionEvent event) {
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    zoomOutBtn.setImageResource(R.drawable.zoomout2);
                    zoomOutMap();
                    break;
                case MotionEvent.ACTION_UP:
                    zoomOutBtn.setImageResource(R.drawable.zoomout1);
                    break;
                default:
                    break;
                }
                return false;
            }
        });

        //create zoom in button.
        zoomInBtn = new ImageButton(webView.getContext());
        zoomInBtn.setImageResource(R.drawable.zoomin1);
        zoomInBtn.setVisibility(View.GONE);
        mContentView.addView(zoomInBtn, ZOOM_IN_PARAMS);
        zoomInBtn.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(final View v, final MotionEvent event) {
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    zoomInBtn.setImageResource(R.drawable.zoomin2);
                    zoomInMap();
                    break;
                case MotionEvent.ACTION_UP:
                    zoomInBtn.setImageResource(R.drawable.zoomin1);
                    break;
                default:
                    break;
                }
                return false;
            }
        });
    }
    /* 090513-[ID_003]-ADD[E]*/

    /**
     * switch to normal view.
     */
    private void switchNormalScreen() {
        Window win = getWindow();
        win.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        imageView.setVisibility(View.VISIBLE);
    }
    /**
     * switch to full screen.
     */
    private void switchFullScreen() {
        Window win = getWindow();
        win.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        imageView.setVisibility(View.GONE);
    }
    /**
     * update map.
     */
    private void updateMap() {
        myMapProgress = ProgressDialog.show(this, PRO_TITLE
                , PRO_CONTENT);
        myMapProgress.setCancelable(true);
        myMapProgress.setOnCancelListener(new OnCancelListener() {
            public void onCancel(final DialogInterface dialog) {
                // TODO Auto-generated method stub
                webView.stopLoading();
            }
        });
        webView.loadUrl(WEB_API_HTML);
        /* 090514-[ID_003] - DEL[S] */
//        showSearchMenu();
        /* 090514-[ID_003] - DEL[E] */
    }

    /**
     * Enable move and zoom hot key on map.
     */
    private void enableMoveHotKey() {
        webView.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(final View arg0, final int keyCode,
                                 final KeyEvent arg2) {
                //Key Down - map move down.
                if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            webView.loadUrl("javascript:moveDown()");
                        }
                    });
                    return true;
                }
                //Key UP - map move up.
                if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            webView.loadUrl("javascript:moveUp()");
                        }
                    });
                    return true;
                }
                //Key Left - map move left.
                if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            webView.loadUrl("javascript:moveLeft()");
                        }
                    });
                    return true;
                }
                //Key Right - map move right.
                if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            webView.loadUrl("javascript:moveRight()");
                        }
                    });
                    return true;
                }
                return enableNormalHotKey(keyCode);
            }
        });
    }
    /* 090514-[ID_003]-ADD[S] */
    /**
     * Zoom in map.
     */
    private void zoomInMap() {
        mHandler.post(new Runnable() {
            public void run() {
                if (webView != null) {
                    webView.loadUrl("javascript:zoomIn()");
                }
            }
        });
    }
    /**
     * Zoom in map.
     */
    private void zoomOutMap() {
        mHandler.post(new Runnable() {
            public void run() {
                if (webView != null) {
                    webView.loadUrl("javascript:zoomOut()");
                }
            }
        });
    }
    /* 090514-[ID_003]-ADD[E] */
    /**
     * private - Enable hot key without move key.
     * @param keyCode key code.
     * @return true false
     */
    private boolean enableNormalHotKey(final int keyCode) {
        //key zoom in - I key.
        if (keyCode == KeyEvent.KEYCODE_I) {
            /* 090514-[ID_003] - CHG[S] */
//            mHandler.post(new Runnable() {
//                public void run() {
//                    webView.loadUrl("javascript:zoomIn()");
//                }
//            });
            zoomInMap();
            /* 090514-[ID_003] - CHG[E] */
            return true;
        }
        //Key zoom out - O key
        if (keyCode == KeyEvent.KEYCODE_O) {
            /* 090514-[ID_003] - CHG[S] */
//            mHandler.post(new Runnable() {
//                public void run() {
//                    webView.loadUrl("javascript:zoomOut()");
//                }
//            });
            zoomOutMap();
            /* 090514-[ID_003] - CHG[E] */
            return true;
        }
      //Key SATELLITE mode - S key
        if (keyCode == KeyEvent.KEYCODE_S) {
            mHandler.post(new Runnable() {
                public void run() {
                    webView.loadUrl("javascript:changeSATELLITE()");
                }
            });
            return true;
        }
      //Key HYBRID mode - H key
        if (keyCode == KeyEvent.KEYCODE_H) {
            mHandler.post(new Runnable() {
                public void run() {
                    webView.loadUrl("javascript:changeHYBRID()");
                }
            });
            return true;
        }
      //Key Terrain mode - T key
        if (keyCode == KeyEvent.KEYCODE_T) {
            mHandler.post(new Runnable() {
                public void run() {
                    webView.loadUrl("javascript:changePHYSICAL()");
                }
            });
            return true;
        }
      //Key Normal mode - N key
        if (keyCode == KeyEvent.KEYCODE_M) {
            mHandler.post(new Runnable() {
                public void run() {
                    webView.loadUrl("javascript:changeNormal()");
                }
            });
            return true;
        }
      //Key refresh page - R key
        if (keyCode == KeyEvent.KEYCODE_R) {
            updateMap();
            return true;
        }
        return false;
    }
    /**
     * disable move hot key - enable zoom and change style map hot key.
     */
    private void disableMoveHotKey() {
        webView.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(final View arg0, final int keyCode,
                                 final KeyEvent arg2) {
                return enableNormalHotKey(keyCode);
            }
        });
    }

    /**
     * catch event keydow.
     * @param keyCode code.
     * @param event keyevent.
     * @return boolean
     */
    @Override
    public final boolean onKeyDown(final int keyCode, final KeyEvent event) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_F:
            if (imageView.getVisibility() == View.VISIBLE) {
                switchFullScreen();
            } else {
                switchNormalScreen();
            }
            break;
        default:
            break;
        }
        return super.onKeyDown(keyCode, event);
    }
    /**
     * Create menu bar.
     * @param menu menu.
     * @return boolean.
     */
    @Override
    public final boolean onCreateOptionsMenu(final Menu menu) {
        super.onCreateOptionsMenu(menu);
        menu.add(0, MENU_SEARCH_ID, 0, MENU_SEARCH_TITLE)
        .setIcon(R.drawable.search);
        menu.add(0, MENU_MAP_ID, 0, MENU_MAP_TITLE)
            .setIcon(R.drawable.normalmap);
        menu.add(0, MENU_SATELLITE_MAP_ID, 0, MENU_SATELLITE_TITLE)
            .setIcon(R.drawable.satellitemap);
        menu.add(0, MENU_HYBIRD_MAP_ID, 0, MENU_HYBIRD_TITLE)
            .setIcon(R.drawable.hybridmap);
        menu.add(0, MENU_PHY_MAP_ID, 0, MENU_TERRIAN_TITLE)
            .setIcon(R.drawable.terrainmap);
        /* 090514-[CHR_002]-ADD[S]*/
        menu.add(0, MENU_HELP_MAP_ID, 0, MENU_HELP_TITLE)
            .setIcon(R.drawable.help);
        menu.add(0, MENU_ABOUT_MAP_ID, 0, MENU_ABOUT_TITLE)
            .setIcon(R.drawable.about);
        /* 090514-[CHR_002]-ADD[E]*/
        /* 090514-[ID_003] - DEL[S] */
//        menuView = menu;
        /* 090514-[ID_003] - DEL[E] */
        return true;
    }

      /**.
     * menu selected
     * @param item menu item
     * @return boolean
     */
    @Override
    public final boolean onOptionsItemSelected(final MenuItem item) {
        switch (item.getItemId()) {
        case MENU_SEARCH_ID:
            /* 090514-[ID_003] - ADD[S] - check title name. */
            String title = (String) item.getTitle();
            if (title.compareTo(MENU_SEARCH_TITLE) == 0) {
            /* 090514-[ID_003] - ADD[E] - check title name. */
                //call java script to show google search form.
                mHandler.post(new Runnable() {
                    public void run() {
                        webView.loadUrl("file:///android_asset/gadgat_map.html");
                        //webView.loadUrl("javascript:showGoogleSearch()");
                       // 
                        disableMoveHotKey();
                        //show stop search menu
                        /* 090514-[ID_003] - DEL[S] */
//                        showStopSearchMenu();
                        /* 090514-[ID_003] - ADD[S] */
                    }
                });
                /* 090514-[ID_003] - ADD[S] - change to stop search menu. */
                item.setTitle(MENU_STOP_SEARCH_TITLE);
                item.setIcon(R.drawable.stopsearch);
            } else if (title.compareTo(MENU_STOP_SEARCH_TITLE) == 0) {
                //call java script to show google search form.
                mHandler.post(new Runnable() {
                    public void run() {
                        webView.loadUrl("javascript:hideGoogleSearch()");
                        webView.loadUrl("javascript:hideResultPanel()");
                        enableMoveHotKey();
                        //show stop search menu
//                        showStopSearchMenu();
                    }
                });
                item.setTitle(MENU_SEARCH_TITLE);
                item.setIcon(R.drawable.search);
            }
            /* 090514-[ID_003] - ADD[E] - change to stop search menu. */
            break;
          /* 090514-[ID_003] - DEL[S] - Don't need more stop search menu. */
//        case MENU_STOP_SEARCH_ID:
//            //call java script to hide google search form.
//            mHandler.post(new Runnable() {
//                public void run() {
//                    webView.loadUrl("javascript:hideGoogleSearch()");
//                    webView.loadUrl("javascript:hideResultPanel()");
//                    enableMoveHotKey();
//                    showSearchMenu();
//                }
//            });
//            break;
            /* 090514-[ID_003] - DEL[E] */
        case MENU_MAP_ID:
            mHandler.post(new Runnable() {
                public void run() {
                    webView.loadUrl("javascript:changeNormal()");
                }
            });
            break;
        case MENU_HYBIRD_MAP_ID:
            mHandler.post(new Runnable() {
                public void run() {
                    webView.loadUrl("javascript:changeHYBRID()");
                }
            });
            break;
        case MENU_PHY_MAP_ID:
            mHandler.post(new Runnable() {
                public void run() {
                    webView.loadUrl("javascript:changePHYSICAL()");
                }
            });
            break;
        case MENU_SATELLITE_MAP_ID:
            mHandler.post(new Runnable() {
                public void run() {
                    webView.loadUrl("javascript:changeSATELLITE()");
                }
            });
            break;
        /* 090514-[CHR_003]-ADD[S]*/
        case MENU_HELP_MAP_ID:
            showMsgDialog(DIALOG_HELP_TITLE, getString(R.string.help_text));
            break;
        case MENU_ABOUT_MAP_ID:
            showMsgDialog(DIALOG_ABOUT_TITLE, getString(R.string.about_text, getVersionNumber()));
            break;
        /* 090514-[CHR_003]-ADD[E]*/
        default:
            break;
        }
        return super.onOptionsItemSelected(item);
    }
    /* 090514-[CHR_002]-ADD[S]*/
    /**
     * show message.
     * @param title String
     * @param err String
     */
    private void showMsgDialog(final String title, final String err) {
          new AlertDialog.Builder(this)
          .setTitle(title)
          .setMessage(err)
          .setPositiveButton("OK", null).setIcon(R.drawable.map)
          .create().show();
    }
    /**
     * Get current version number.
     * @return String.
     */
    private String getVersionNumber() {
        String version = "?";
        try {
            PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
            version = pi.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("OSP ERROR", "Package name not found", e);
        }
        return version;
    }
    /* 090514-[CHR_002]-ADD[E]*/

    /* 090514-[ID_003] - DEL[S] - Don't need to more stop search menu. */
//    /**
//     * show search menu.
//     */
//    private void showSearchMenu() {
//            //hide menu disable search
//        if (menuView == null
//                  || menuView.findItem(MENU_STOP_SEARCH_ID) == null) {
//            return;
//        }
//        menuView.removeItem(MENU_STOP_SEARCH_ID);
//        //show menu search
//        menuView.add(0, MENU_SEARCH_ID, 0, MENU_SEARCH_TITLE)
//                .setIcon(R.drawable.search);
//    }

//    /**
//     * show stop search menu.
//     */
//    private void showStopSearchMenu() {
//        if (menuView == null
//                || menuView.findItem(MENU_SEARCH_ID) == null) {
//            return;
//        }
//        //hide menu search
//        menuView.removeItem(MENU_SEARCH_ID);
//        //add menu disable search
//        menuView.add(0, MENU_STOP_SEARCH_ID, 1, MENU_STOP_SEARCH_TITLE)
//                .setIcon(R.drawable.stopsearch);
//    }
    /* 090514-[ID_003] - DEL[E] - Don't need to more stop search menu. */
}
